﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ORMAC.CodeGen
{
    public class SqlTypeMap
    {
        public static string Map(string key,bool isSqlType)
        {
            if (!isSqlType)
                return key;
            if (m_Map.ContainsKey(key))
                return m_Map[key];
            else
            {
                throw new ORMACException(string.Format("SQL type %s not ssupported by ORMAC",key));
            }

        }
        public static string Default(string key)
        {
            if (m_Defaults.ContainsKey(key))
                return m_Defaults[key];
            else
            {
                throw new ORMACException(string.Format("Default type %s not ssupported by ORMAC", key));
            }
        }
        private static Dictionary<string, string> m_Map = new Dictionary<string, string>
        {
            {"bit","bool"},
            {"text","string"},
            {"ntext","string"},
            {"varchar","string"},
            {"nvarchar","string"},
            {"char","string"},
            {"nchar","string"},
            {"tinyint","int"},
            {"smallint","int"},
            {"int","int"},
            {"bigint","int"},
            {"float","float"},
            {"real","decimal"},
            {"decimal","decimal"},
            {"datetime","DateTime"},
            {"date","DateTime"},
            {"time","DateTime"},
            {"smalldatetime","DateTime"},
            {"money","decimal"},
            {"varbinary","Byte []"},
            {"image","Byte []"},
        };
        private static Dictionary<string, string> m_Defaults = new Dictionary<string, string>
        {
            {"text","''"},
            {"ntext","''"},
            {"varchar","''"},
            {"nvarchar","''"},
            {"char","''"},
            {"nchar","''"},
            {"tinyint","0"},
            {"smallint","0"},
            {"int","0"},
            {"bigint","0"},
            {"float","0"},
            {"real","0"},
            {"decimal","0"},
            {"datetime","'1/1/2000'"},
            {"date","'1/1/2000'"},
            {"time","'1/1/2000'"},
            {"smalldatetime","'1/1/2000'"},
            {"money","0"},
            {"varbinary",""},
        };
    }
}
